package com.meilai.project.controller.web.business.installOrder;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.meilai.project.dto.CommonResult;
import com.meilai.project.dto.app.AppReplacePointDTO;
import com.meilai.project.dto.business.installOrder.*;
import com.meilai.project.entity.business.installOrder.WorkOrder;
import com.meilai.project.service.business.installOrder.WorkOrderService;
import com.meilai.project.service.business.media.MediaPointService;
import com.meilai.project.vo.business.installOrder.*;
import com.meilai.project.vo.business.media.MediaPointAreaVO;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Api(value = "工单管理", tags = {"工单管理"})
@RestController
@RequestMapping("api/web/workOrder")
public class WorkOrderController {
    @Autowired
    private WorkOrderService service;

    @Autowired
    private MediaPointService mediaPointService;

    @ApiOperation(value = "批量替换工单点位", notes = "批量替换工单点位")
    @ApiResponses({@ApiResponse(code = CommonResult.SUCCESS, message = "操作成功"), @ApiResponse(code = CommonResult.VALIDATE_FAILED, message = "参数校验失败"), @ApiResponse(code = CommonResult.UNAUTHORIZED, message = "未认证"), @ApiResponse(code = CommonResult.FORBIDDEN, message = "未授权"), @ApiResponse(code = CommonResult.FAILED, message = "操作失败")})
    @ResponseBody
    @PostMapping("batchReplacePoint")
    public CommonResult replaceWorkOrderPoint(@RequestBody @Valid @ApiParam(name = "批量替换工单点位", value = "传入json格式", required = true) WebBatchReplacePointDTO dto, BindingResult bindingResult) {
        if (bindingResult.hasErrors()) return new CommonResult().validateFailed(bindingResult);
        return new CommonResult().success(service.batchReplacePoint(dto));
    }

    @ApiOperation(value = "替换工单点位", notes = "替换工单点位")
    @ApiResponses({@ApiResponse(code = CommonResult.SUCCESS, message = "操作成功"), @ApiResponse(code = CommonResult.VALIDATE_FAILED, message = "参数校验失败"), @ApiResponse(code = CommonResult.UNAUTHORIZED, message = "未认证"), @ApiResponse(code = CommonResult.FORBIDDEN, message = "未授权"), @ApiResponse(code = CommonResult.FAILED, message = "操作失败")})
    @ResponseBody
    @PostMapping("replacePoint")
    public CommonResult replaceWorkOrderPoint(@RequestBody @Valid @ApiParam(name = "替换点位对象", value = "传入json格式", required = true) AppReplacePointDTO dto, BindingResult bindingResult) {
        if (bindingResult.hasErrors()) return new CommonResult().validateFailed(bindingResult);
        return new CommonResult().success(service.replacePoint(dto));
    }


    @ApiOperation(value = "工人列表", notes = "工人列表", response = WorkerVO.class)
    @ApiResponses({@ApiResponse(code = CommonResult.SUCCESS, message = "操作成功"), @ApiResponse(code = CommonResult.VALIDATE_FAILED, message = "参数校验失败"), @ApiResponse(code = CommonResult.UNAUTHORIZED, message = "未认证"), @ApiResponse(code = CommonResult.FORBIDDEN, message = "未授权"), @ApiResponse(code = CommonResult.FAILED, message = "操作失败")})
    @ResponseBody
    @GetMapping("listWorker")
    public CommonResult listWorker(@ApiParam(name = "name", value = "姓名", required = false) @RequestParam(value = "name", required = false) String name, @ApiParam(name = "mobile", value = "手机号", required = false) @RequestParam(value = "mobile", required = false) String mobile) {
        WorkerDTO workerDTO = new WorkerDTO();
        workerDTO.setName(name);
        workerDTO.setMobile(mobile);

        return new CommonResult().success(service.listWorker(workerDTO));
    }


    @ApiOperation(value = "销售单列表", notes = "销售单列表", response = WorkOrderBillSaleVO.class)
    @ApiResponses({@ApiResponse(code = CommonResult.SUCCESS, message = "操作成功"), @ApiResponse(code = CommonResult.VALIDATE_FAILED, message = "参数校验失败"), @ApiResponse(code = CommonResult.UNAUTHORIZED, message = "未认证"), @ApiResponse(code = CommonResult.FORBIDDEN, message = "未授权"), @ApiResponse(code = CommonResult.FAILED, message = "操作失败")})
    @ResponseBody
    @GetMapping("listBillSale")
    public CommonResult listBillSale(@ApiParam(name = "page", value = "当前页", required = true) @RequestParam(value = "page", defaultValue = "1", required = true) Integer page, @ApiParam(name = "page_size", value = "每页数量", required = true) @RequestParam(value = "page_size", defaultValue = "10", required = true) Integer page_size, @ApiParam(name = "work_order_type_id", value = "要创建的工单类型", required = true) @RequestParam(value = "work_order_type_id", required = false) Integer work_order_type_id, @ApiParam(name = "name", value = "销售单甲方名称-查询模糊匹配", required = false) @RequestParam(value = "name", required = false) String name

    ) {
        WorkOrderBillSaleDTO workOrderBillSaleDTO = new WorkOrderBillSaleDTO();
        workOrderBillSaleDTO.setName(name);
        workOrderBillSaleDTO.setWork_order_type_id(work_order_type_id);

        return new CommonResult().success(service.listPageBillSale(page, page_size, workOrderBillSaleDTO));
    }

    @ApiOperation(value = "楼盘列表-选楼盘", notes = "楼盘列表-选楼盘", response = WorkOrderBuildingVO.class)
    @ApiResponses({@ApiResponse(code = CommonResult.SUCCESS, message = "操作成功"), @ApiResponse(code = CommonResult.VALIDATE_FAILED, message = "参数校验失败"), @ApiResponse(code = CommonResult.UNAUTHORIZED, message = "未认证"), @ApiResponse(code = CommonResult.FORBIDDEN, message = "未授权"), @ApiResponse(code = CommonResult.FAILED, message = "操作失败")})
    @ResponseBody
    @GetMapping("listPageBuilding")
    public CommonResult listPageBuilding(@ApiParam(name = "page", value = "当前页", required = true) @RequestParam(value = "page", defaultValue = "1", required = true) Integer page, @ApiParam(name = "page_size", value = "每页数量", required = true) @RequestParam(value = "page_size", defaultValue = "10", required = true) Integer page_size, @ApiParam(name = "work_order_type_id", value = "要创建的工单类型", required = true) @RequestParam(value = "work_order_type_id", required = false) Integer work_order_type_id, @ApiParam(name = "name", value = "楼盘名称-查询模糊匹配", required = false) @RequestParam(value = "name", required = false) String name, @ApiParam(name = "adcode", value = "行政区划", required = false) @RequestParam(value = "adcode", required = false) String adcode, @RequestParam(value = "media_type_id", required = false) Long media_type_id) {

        WorkOrderBuidingDTO workOrderBuidingDTO = new WorkOrderBuidingDTO();
        workOrderBuidingDTO.setName(name);
        workOrderBuidingDTO.setWork_order_type_id(work_order_type_id);
        workOrderBuidingDTO.setAdcode(adcode);
        workOrderBuidingDTO.setMedia_type_id(media_type_id);
        return new CommonResult().success(service.listPageBuilding(page, page_size, workOrderBuidingDTO));
    }

    @ApiOperation("全选楼盘操作")
    @GetMapping("/allSelectBuildingList")
    public CommonResult a(@RequestParam(value = "name", required = false) String name, @RequestParam(value = "adcode", required = false) String adcode, @RequestParam(value = "media_type_id", required = false) Long media_type_id) {
        WorkOrderBuidingDTO workOrderBuidingDTO = new WorkOrderBuidingDTO();
        workOrderBuidingDTO.setName(name);
        workOrderBuidingDTO.setAdcode(adcode);
        workOrderBuidingDTO.setMedia_type_id(media_type_id);
        return new CommonResult().success(service.listPageBuildingForCheckWorkOrder(workOrderBuidingDTO));
    }

    @ApiOperation(value = "楼盘列表-分配工人时选楼盘", notes = "楼盘列表-分配工人时选楼盘", response = WorkOrderBuildingMatchWorkerVO.class)
    @ApiResponses({@ApiResponse(code = CommonResult.SUCCESS, message = "操作成功"), @ApiResponse(code = CommonResult.VALIDATE_FAILED, message = "参数校验失败"), @ApiResponse(code = CommonResult.UNAUTHORIZED, message = "未认证"), @ApiResponse(code = CommonResult.FORBIDDEN, message = "未授权"), @ApiResponse(code = CommonResult.FAILED, message = "操作失败")})
    @ResponseBody
    @PostMapping("listBuildingMacthWorker")
    public CommonResult listBuildingMacthWorker(@ApiParam(name = "buildingIds", value = "选中楼盘ID集合", required = false) @RequestBody List<String> listBuildingIds) {
//        List<String> listBuildingIds = Arrays.asList(buildingIds);
        return new CommonResult().success(service.listBuildingMatchWorker(listBuildingIds));
    }

    @ApiOperation(value = "销售单列表-对应楼盘", notes = "销售单列表-对应楼盘", response = WorkOrderBuildingOfBillSaleVO.class)
    @ApiResponses({@ApiResponse(code = CommonResult.SUCCESS, message = "操作成功"), @ApiResponse(code = CommonResult.VALIDATE_FAILED, message = "参数校验失败"), @ApiResponse(code = CommonResult.UNAUTHORIZED, message = "未认证"), @ApiResponse(code = CommonResult.FORBIDDEN, message = "未授权"), @ApiResponse(code = CommonResult.FAILED, message = "操作失败")})
    @ResponseBody
    @GetMapping("listBuildingOfBillSale")
    public CommonResult listBuildingOfBillSale(@ApiParam(name = "bill_sale_id", value = "选中销售单ID", required = true) @RequestParam(value = "bill_sale_id", required = true) Long bill_sale_id, @ApiParam(name = "choose_id", value = "点位选择id", required = false) @RequestParam(value = "choose_id", required = false) Long choose_id, @ApiParam(name = "daterange_id", value = "日期范围id", required = false) @RequestParam(value = "daterange_id", required = false) Long daterange_id) {

        return new CommonResult().success(service.listBuildingOfBillSale(bill_sale_id, choose_id, daterange_id));
    }

    @ApiOperation(value = "保存工单", notes = "保存工单")
    @ApiResponses({@ApiResponse(code = CommonResult.SUCCESS, message = "操作成功"), @ApiResponse(code = CommonResult.VALIDATE_FAILED, message = "参数校验失败"), @ApiResponse(code = CommonResult.UNAUTHORIZED, message = "未认证"), @ApiResponse(code = CommonResult.FORBIDDEN, message = "未授权"), @ApiResponse(code = CommonResult.FAILED, message = "操作失败")})
    @ResponseBody
    @PostMapping("save")
    public CommonResult save(@RequestBody @Valid @ApiParam(name = "传输对象", value = "传入json格式", required = true) WorkOrderDTO dto, BindingResult bindingResult) {
        if (bindingResult.hasErrors()) return new CommonResult().validateFailed(bindingResult);
        try {
            if (service.saveWorkOrder(dto)) {
                return new CommonResult().success("新增成功");
            } else {
                return new CommonResult().failed("新增失败");
            }
        } catch (Exception e) {
            return new CommonResult().failed(e.getMessage());
        }
    }

    @ApiOperation(value = "工单列表分页查询", notes = "工单列表分页查询", response = WorkOrderVO.class)
    @ApiResponses({@ApiResponse(code = CommonResult.SUCCESS, message = "操作成功"), @ApiResponse(code = CommonResult.VALIDATE_FAILED, message = "参数校验失败"), @ApiResponse(code = CommonResult.UNAUTHORIZED, message = "未认证"), @ApiResponse(code = CommonResult.FORBIDDEN, message = "未授权"), @ApiResponse(code = CommonResult.FAILED, message = "操作失败")})
    @ResponseBody
    @GetMapping("list")
    public CommonResult list(@ApiParam(name = "page", value = "当前页", required = true) @RequestParam(value = "page", defaultValue = "1", required = true) Integer page, @ApiParam(name = "page_size", value = "每页数量", required = true) @RequestParam(value = "page_size", defaultValue = "10", required = true) Integer page_size, @ApiParam(name = "execute_status", value = "执行状态", required = false) @RequestParam(value = "execute_status", required = false) Integer execute_status, @ApiParam(name = "name", value = "姓名", required = false) @RequestParam(value = "name", required = false) String name, @ApiParam(name = "deadline_date_min", value = "截止日期最小值，时间段搜索的起始，yyyy-MM-dd", required = false) @RequestParam(value = "deadline_date_min", required = false) String deadline_date_min, @ApiParam(name = "deadline_date_max", value = "截止日期最大值，时间段搜索的结束，yyyy-MM-dd", required = false) @RequestParam(value = "deadline_date_max", required = false) String deadline_date_max, @ApiParam(name = "work_order_type_id", value = "工单类型id", required = true) @RequestParam(value = "work_order_type_id", defaultValue = "1", required = true) Integer work_order_type_id, @ApiParam(name = "media_type_ids", value = "媒体类型") @RequestParam(value = "media_type_ids", required = false) List<Long> media_type_ids) {
        WorkOrderSearchDTO searchDTO = new WorkOrderSearchDTO();
        searchDTO.setExecute_status(execute_status);
        searchDTO.setName(name);
        searchDTO.setDeadline_date_min(deadline_date_min);
        searchDTO.setDeadline_date_max(deadline_date_max);
        searchDTO.setWork_order_type_id(work_order_type_id);
        searchDTO.setMedia_type_ids(media_type_ids);
        return new CommonResult().success(service.selectPageList(page, page_size, searchDTO));
    }

    @ApiOperation(value = "各工单类型总数量", notes = "各工单类型总数量", response = Map.class)
    @ApiResponses({@ApiResponse(code = CommonResult.SUCCESS, message = "操作成功"), @ApiResponse(code = CommonResult.VALIDATE_FAILED, message = "参数校验失败"), @ApiResponse(code = CommonResult.UNAUTHORIZED, message = "未认证"), @ApiResponse(code = CommonResult.FORBIDDEN, message = "未授权"), @ApiResponse(code = CommonResult.FAILED, message = "操作失败")})
    @ResponseBody
    @GetMapping("listWorkOrderNumOfType")
    public CommonResult listWorkOrderNumOfType() {

        return new CommonResult().success(service.listWorkOrderNumOfType());
    }

    @ApiOperation(value = "各工单类型进度", notes = "各工单类型进度", response = Map.class)
    @ApiResponses({@ApiResponse(code = CommonResult.SUCCESS, message = "操作成功"), @ApiResponse(code = CommonResult.VALIDATE_FAILED, message = "参数校验失败"), @ApiResponse(code = CommonResult.UNAUTHORIZED, message = "未认证"), @ApiResponse(code = CommonResult.FORBIDDEN, message = "未授权"), @ApiResponse(code = CommonResult.FAILED, message = "操作失败")})
    @ResponseBody
    @GetMapping("getAllWorkOrderProgressByTypeId")
    public CommonResult getAllWorkOrderProgressByTypeId(@RequestParam("work_order_type_id") Long work_order_type_id) {
        return new CommonResult().success(service.getAllWorkOrderProgressByTypeId(work_order_type_id));
    }

    @ApiOperation(value = "删除", notes = "删除")
    @ApiResponses({@ApiResponse(code = CommonResult.SUCCESS, message = "操作成功"), @ApiResponse(code = CommonResult.VALIDATE_FAILED, message = "参数校验失败"), @ApiResponse(code = CommonResult.UNAUTHORIZED, message = "未认证"), @ApiResponse(code = CommonResult.FORBIDDEN, message = "未授权"), @ApiResponse(code = CommonResult.FAILED, message = "操作失败")})
    @ResponseBody
    @DeleteMapping("delete")
    public CommonResult delete(@RequestParam(value = "id", required = true) Long id) {
        try {
            if (service.delete(id)) {
                return new CommonResult().success("删除成功");
            } else {
                return new CommonResult().failed("删除失败");
            }
        } catch (Exception e) {
            return new CommonResult().failed(e.getMessage());
        }
    }

    @ApiOperation(value = "手动关闭", notes = "手动关闭")
    @ApiResponses({@ApiResponse(code = CommonResult.SUCCESS, message = "操作成功"), @ApiResponse(code = CommonResult.VALIDATE_FAILED, message = "参数校验失败"), @ApiResponse(code = CommonResult.UNAUTHORIZED, message = "未认证"), @ApiResponse(code = CommonResult.FORBIDDEN, message = "未授权"), @ApiResponse(code = CommonResult.FAILED, message = "操作失败")})
    @ResponseBody
    @DeleteMapping("handClosed")
    public CommonResult hand_closed(@RequestParam(value = "id", required = true) Long id) {
        try {
            if (service.handClosed(id)) {
                return new CommonResult().success("手动关闭成功");
            } else {
                return new CommonResult().failed("手动关闭失败");
            }
        } catch (Exception e) {
            return new CommonResult().failed(e.getMessage());
        }
    }

    @PostMapping("genWorkOrderReport")
    @ApiOperation(value = "生成工单报告")
    public CommonResult genWorkOrderReport(@RequestBody WorkOrderReportInfoDTO data) {
        try {
//            Optional<HttpSession> session = Optional.ofNullable(((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest().getSession(false));
//            String tenantName = session.isPresent() ? session.get().getAttribute("tenantName").toString() : "master";
            Runnable runnable = () -> {
                service.genWorkOrderReport("master", data);
            };
            new Thread(runnable).start();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return new CommonResult().successForMessage("后台正在生成报告，请稍后刷新页面进行下载");
    }

    @ApiOperation(value = "工单详情", notes = "工单详情", response = WorkOrderDetailVO.class)
    @ApiResponses({@ApiResponse(code = CommonResult.SUCCESS, message = "操作成功"), @ApiResponse(code = CommonResult.VALIDATE_FAILED, message = "参数校验失败"), @ApiResponse(code = CommonResult.UNAUTHORIZED, message = "未认证"), @ApiResponse(code = CommonResult.FORBIDDEN, message = "未授权"), @ApiResponse(code = CommonResult.FAILED, message = "操作失败")})
    @ResponseBody
    @GetMapping("detail/{id}")
    public CommonResult detail(@ApiParam(name = "id", value = "工单id", required = true) @PathVariable("id") Long id) {
        return new CommonResult().success(service.getWorkOrderDetailById(id));
    }

    @PostMapping("edit")
    @ApiOperation(value = "修改工单", notes = "修改工单")
    @ApiResponses({@ApiResponse(code = CommonResult.SUCCESS, message = "操作成功"), @ApiResponse(code = CommonResult.VALIDATE_FAILED, message = "参数校验失败"), @ApiResponse(code = CommonResult.UNAUTHORIZED, message = "未认证"), @ApiResponse(code = CommonResult.FORBIDDEN, message = "未授权"), @ApiResponse(code = CommonResult.FAILED, message = "操作失败")})
    @ResponseBody
    public CommonResult edit(@RequestBody WorkOrderDTO dto) {
        if (service.updateWorkOrder(dto)) {
            return new CommonResult().success("修改成功");
        }
        return new CommonResult().failed("修改失败");
    }

    @PostMapping("editDeadline")
    @ApiOperation(value = "修改工单截止时间", notes = "修改工单截止时间")
    @ApiResponses({@ApiResponse(code = CommonResult.SUCCESS, message = "操作成功"), @ApiResponse(code = CommonResult.VALIDATE_FAILED, message = "参数校验失败"), @ApiResponse(code = CommonResult.UNAUTHORIZED, message = "未认证"), @ApiResponse(code = CommonResult.FORBIDDEN, message = "未授权"), @ApiResponse(code = CommonResult.FAILED, message = "操作失败")})
    @ResponseBody
    public CommonResult editDeadline(@RequestBody WorkOrderUpdateDeadlineDTO dto) {
        if (service.updateWorkOrderDeadLine(dto)) {
            return new CommonResult().success("修改成功");
        }
        return new CommonResult().failed("修改失败");
    }

    @ApiOperation(value = "进度查看-楼盘提交情况", notes = "进度查看-楼盘提交情况", response = WorkOrderProcessOfBuildingVO.class)
    @ApiResponses({@ApiResponse(code = CommonResult.SUCCESS, message = "操作成功"), @ApiResponse(code = CommonResult.VALIDATE_FAILED, message = "参数校验失败"), @ApiResponse(code = CommonResult.UNAUTHORIZED, message = "未认证"), @ApiResponse(code = CommonResult.FORBIDDEN, message = "未授权"), @ApiResponse(code = CommonResult.FAILED, message = "操作失败")})
    @ResponseBody
    @GetMapping("listProcessOfBuilding")
    public CommonResult listProcessOfBuilding(@ApiParam(name = "work_order_id", value = "工单id", required = true) @RequestParam(value = "work_order_id", required = true) Long work_order_id, @ApiParam(name = "name", value = "楼盘名称", required = false) @RequestParam(value = "name", required = false) String name, @ApiParam(name = "work_order_type_id", value = "工单类型id", required = true) @RequestParam(value = "work_order_type_id", required = true) Integer work_order_type_id) {

        return new CommonResult().success(service.listProcessOfBuilding(work_order_id, name, work_order_type_id));
    }

    @ApiOperation(value = "进度查看-获取楼盘下提交设备", notes = "进度查看-获取楼盘下提交设备", response = SubmissionDetailVO.class)
    @ApiResponses({@ApiResponse(code = CommonResult.SUCCESS, message = "操作成功"), @ApiResponse(code = CommonResult.VALIDATE_FAILED, message = "参数校验失败"), @ApiResponse(code = CommonResult.UNAUTHORIZED, message = "未认证"), @ApiResponse(code = CommonResult.FORBIDDEN, message = "未授权"), @ApiResponse(code = CommonResult.FAILED, message = "操作失败")})
    @ResponseBody
    @GetMapping("getWorkOrderSubmissionByBuildingId")
    public CommonResult getWorkOrderSubmissionByBuildingId(@ApiParam(name = "page", value = "当前页", required = true) @RequestParam(value = "page", defaultValue = "1", required = true) Integer page, @ApiParam(name = "page_size", value = "每页数量", required = true) @RequestParam(value = "page_size", defaultValue = "10", required = true) Integer page_size, @ApiParam(name = "work_order_id", value = "工单id", required = true) @RequestParam(value = "work_order_id", required = true) Long work_order_id, @ApiParam(name = "building_id", value = "楼盘ID", required = true) @RequestParam(value = "building_id", required = true) Long building_id, @ApiParam(name = "code", value = "设备编号", required = true) @RequestParam(value = "code", required = false) String code, @ApiParam(name = "is_submit", value = "是否提交", required = true) @RequestParam(value = "is_submit", required = true) Boolean is_submit) {

        return new CommonResult().success(service.getWorkOrderSubmissionByBuildingId(page, page_size, work_order_id, building_id, code, is_submit));
    }

    @ApiOperation(value = "查询未占用的点位", notes = "查询未占用的点位", response = MediaPointAreaVO.class)
    @ApiResponses({@ApiResponse(code = CommonResult.SUCCESS, message = "操作成功"), @ApiResponse(code = CommonResult.VALIDATE_FAILED, message = "参数校验失败"), @ApiResponse(code = CommonResult.UNAUTHORIZED, message = "未认证"), @ApiResponse(code = CommonResult.FORBIDDEN, message = "未授权"), @ApiResponse(code = CommonResult.FAILED, message = "操作失败")})
    @ResponseBody
    @GetMapping("getUnlockedPoint")
    public CommonResult getUnlockedPoint(@ApiParam(name = "page", value = "当前页", required = true) @RequestParam(value = "page", defaultValue = "1", required = true) Integer page, @ApiParam(name = "page_size", value = "每页数量", required = true) @RequestParam(value = "page_size", defaultValue = "10", required = true) Integer page_size, @ApiParam(name = "point_type_id", value = "点位类型ID", required = true) @RequestParam(value = "point_type_id") Long point_type_id, @ApiParam(name = "start_time", value = "开始时间", required = true) @RequestParam(value = "start_time") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime start_time, @ApiParam(name = "end_time", value = "结束时间", required = true) @RequestParam(value = "end_time") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime end_time, @ApiParam(name = "adcode", value = "行政区划", required = false) @RequestParam(value = "adcode", required = false) String adcode, @ApiParam(name = "building_id", value = "项目ID", required = true) @RequestParam(value = "building_id", required = false) Long building_id, @ApiParam(name = "code", value = "编号", required = true) @RequestParam(value = "code", required = false) String code) {
        return new CommonResult().success(mediaPointService.getUnlockedPoint(page, page_size, adcode, building_id, code, point_type_id, start_time, end_time));
    }


    @ApiOperation(value = "工单列表不分页查询", notes = "工单列表不分页查询", response = WorkOrder.class)
    @ApiResponses({@ApiResponse(code = CommonResult.SUCCESS, message = "操作成功"), @ApiResponse(code = CommonResult.VALIDATE_FAILED, message = "参数校验失败"), @ApiResponse(code = CommonResult.UNAUTHORIZED, message = "未认证"), @ApiResponse(code = CommonResult.FORBIDDEN, message = "未授权"), @ApiResponse(code = CommonResult.FAILED, message = "操作失败")})
    @ResponseBody
    @GetMapping("allList")
    public CommonResult list() {
        return new CommonResult().success(service.list(Wrappers.<WorkOrder>lambdaQuery().isNull(WorkOrder::getDeleted_at)));
    }

    @ApiOperation(value = "生成图片包", notes = "生成图片包")
    @ApiResponses({@ApiResponse(code = CommonResult.SUCCESS, message = "操作成功"), @ApiResponse(code = CommonResult.VALIDATE_FAILED, message = "参数校验失败"), @ApiResponse(code = CommonResult.UNAUTHORIZED, message = "未认证"), @ApiResponse(code = CommonResult.FORBIDDEN, message = "未授权"), @ApiResponse(code = CommonResult.FAILED, message = "操作失败")})
    @ResponseBody
    @GetMapping("createImgPackage")
    public CommonResult createImgPackage(@RequestParam("work_order_id") Long work_order_id) {
        Runnable runnable = () -> {
            service.createImgPackage(work_order_id);
        };
        new Thread(runnable).start();
        return new CommonResult().success();
    }

    @GetMapping("export_work_order_point_detail")
    @ApiOperation(value = "导出工单详细点位")
    public void exportWorkOrderPointDetail(HttpServletResponse response, @RequestParam(value = "id") Long id, @RequestParam(value = "name") String name) {
        service.exportWorkOrderPointDetail(id, name, response);
    }

    @PostMapping("assignWorkers")
    @ApiOperation(value = "分配工人")
    public CommonResult assignWorkers(@RequestBody WorkOrderAssignWorkersDTO workOrderAssignWorkersDTO) {
        return new CommonResult().success(service.assignWorkers(workOrderAssignWorkersDTO));
    }
}
